<template>
  <div class="app-container">
    <div class="filter-container" style="display:flex; justify-content: space-between;">
      <el-dropdown>
        <el-button type="danger" size="small">
          黑名单设置<i class="el-icon-arrow-down el-icon--right"></i>
        </el-button>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item>禁止评论</el-dropdown-item>
          <el-dropdown-item>禁止访问</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
      <div>
        <el-input v-model="listQuery.title" placeholder="用户名" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
        <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
        搜索
      </el-button>
    </div>
  </div>
    <el-table
      v-loading="listLoading"
      :data="list"
      border
      fit
      highlight-current-row
      style="width: 100%;"
      ref="multipleTable"
      @selection-change="handleSelectionChange">

      <el-table-column type="selection" width="55">
      </el-table-column>
      <el-table-column label="用户" min-width="150px">
        <template slot-scope="{row}">
          <div style="display: flex; align-item: center;">
            <!-- :src="row.user.avater" -->
            <img src="../../assets/login.gif" style="width:50px; height:50px; border-radius:100%; margin-right:10px;">
            <div style="display:flex;flex-direction:column;justify-content:span-between;">
              <span>{{ row.user.username }}</span>
            </div>
          </div>
        </template>
      </el-table-column>
      
      <el-table-column label="消费总额" width="110px" align="center">
        <template slot-scope="{row}">
          <span>{{ row.sub_count }}</span>
        </template>
      </el-table-column>

      <el-table-column label="创建时间" width="150px" align="center">
        <template slot-scope="{row}">
          <span>{{ row.created_time }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="280" class-name="small-padding fixed-width">
        <template slot-scope="{row, $index}">
          <el-button size="mini" type="success" @click="openInfo(row.user.id)">
            详情
          </el-button>
          <el-button size="mini" type="primary" style="margin-right:10px;">
            联系用户
          </el-button>

          <el-dropdown>
            <el-button type="danger" size="mini">
              黑名单设置<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>

            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item>禁止评论</el-dropdown-item>
              <el-dropdown-item>禁止访问</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
      <info ref="info"></info>
  </div>
</template>

<script>
import { fetchList } from '@/api/user'
import waves from '@/directive/waves' 
import Tinymce from '@/components/Tinymce'
import { parseTime } from '@/utils'
import Pagination from '@/components/Pagination'
import info from './info'

export default {
  name: 'ComplexTable',
  components: { Pagination, Tinymce, info },
  directives: { waves },
  data() {
    return {
      tablekey: 0,
      list: [],
      total: 0,
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20,
        title: undefined,
      },
      multipleSelection: []
    }
  },
  created() {
    this.getList()
  },
  methods: {
    openInfo(id) {
      this.$refs.info.open(id)
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    getList() {
      this.listLoading = true
      fetchList(this.listQuery).then(response => {
        console.log(response)
        this.list = response.data.items
        this.total = response.data.total

        setTimeout(() => {
          this.listLoading = false
        }, 1.5 * 1000)
      })
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    }
  }
}
</script>
